package OrderService

import (
	"context"
	"gdshop-font-api-go/app/request/OrderReq"
	"gdshop-font-api-go/library/response"
	"gdshop-font-api-go/library/tools"
	"gdshop-font-api-go/rpc/request"
	"gdshop-font-api-go/rpc/service"
	_ "github.com/hprose/hprose-golang/rpc/fasthttp"
)

// Confirm 用户确认订单 判断状态，必须是 4待收货 才可以确认订单
func Confirm(ctx context.Context, parames *OrderReq.Confirm) *response.JsonResponse {
	if !IsMyOrder(ctx, parames.OrderId, int(parames.MemberId)) {
		return response.FailByRequestMessage(nil, "请勿操作别人的订单")
	}

	client := tools.GetRpcClient()
	var orderService *service.OrderService
	client.UseService(&orderService)
	jieguo, err := orderService.MemberConfirmOrder(&request.MemberConfirmOrder{
		OrderId:  parames.OrderId,
		MemberId: parames.MemberId,
	})
	if err != nil {
		return response.RpcFailByRequestMessage(nil, err.Error())
	}

	return jieguo
}
